package com.laizhenghua.share.device.controller;

import com.laizhenghua.share.common.core.domain.R;
import com.laizhenghua.share.common.core.web.controller.BaseController;
import com.laizhenghua.share.device.domain.vo.StationVo;
import com.laizhenghua.share.device.service.IDeviceService;
import com.share.common.security.annotation.RequiresLogin;
import feign.RequestLine;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @Description
 * @Author laizh
 * @Date 2025/7/19 18:17
 **/
@Tag(name = "设备API")
@RestController
@RequestMapping("/device")
public class DeviceController extends BaseController {
    private final IDeviceService iDeviceService;

    @Autowired
    public DeviceController(IDeviceService iDeviceService) {
        this.iDeviceService = iDeviceService;
    }

    @Operation(summary = "获取附近站点信息列表")
    @GetMapping("/nearby/station")
    @Parameters({
            @Parameter(name = "longitude", description = "经度", required = true),
            @Parameter(name = "latitude", description = "纬度", required = true),
            @Parameter(name = "radius", description = "半径"),
    })
    public R<List<StationVo>> nearbyStation(
            @RequestParam("longitude") String longitude,
            @RequestParam("latitude") String latitude,
            @RequestParam(name = "radius", required = false, defaultValue = "5") Integer radius) {
        return iDeviceService.nearbyStation(longitude, latitude, radius);
    }

    @Operation(summary = "根据id和经纬度获取门店详情")
    @GetMapping("/station/detail/{id}/{longitude}/{latitude}")
    @Parameters({
            @Parameter(name = "longitude", description = "当前用户所在经度", required = true),
            @Parameter(name = "latitude", description = "当前用户所在纬度", required = true),
            @Parameter(name = "id", description = "站点id", required = true)
    })
    public R<StationVo> stationDetail(
            @PathVariable("id") Long id,
            @PathVariable("longitude") String longitude,
            @PathVariable("latitude") String latitude) {
        return iDeviceService.stationDetail(id, longitude, latitude);
    }

    @RequiresLogin
    @Operation(summary = "扫码充电")
    @GetMapping("/scan-change/{cabinetNo}")
    @Parameter(name = "cabinetNo", description = "柜机编号", required = true)
    public R<?> scanChange(@PathVariable("cabinetNo") String cabinetNo) {
        return iDeviceService.scanChange(cabinetNo);
    }
}
